<?php

namespace App\Http\Controllers\admin;

use Illuminate\Http\Request;
use App\Http\Requests;
use App\Http\Controllers\Controller;
use Gregwar\Captcha\CaptchaBuilder;
use App\Models\User;
//use session;

class LoginController extends Controller
{
    /**     * Display a listing of the resource.

     *
     * @return \Illuminate\Http\Response
     */
    public function index()
    
     {
        return view('admin.login');
     }

     public function doLogin(request $request)
     {  
             


         $user = new User();
          $ob = $user->index($request);
          //dd($ob);
            if($ob){
                 session(['adminuser'=>$ob]);
                   return redirect('admin/demo');
          }else{
               return back()->with('msg', '登录失败：用户名或密码错误');
           }
		      $mycode = session('mycode');
        if($mycode != $request->input('mycode')){
           // 不一致则跳转回上一页
            return back()->with('msg', '登录失败：验证码错误');
       }

        //dd($request);
       
       // return 111111111;
        //return redirect('admin/demo');
         

            
    }

     public function capth()
      {  $builder = new CaptchaBuilder;   

         $builder->build( 140,  50, null);
          $phrase = $builder->getPhrase();
          session()->flash('mycode', $phrase);
          header('Content-Type: image/jpeg'); 

        
      
       return response($builder->output())->header('Content-type', 'image/jpeg');
     }

    public function over()
    {
       session()->flush();
        return redirect('admin/login');
    }

}
